package com.thirdgroup.dao.impl;

import com.thirdgroup.dao.ManagerInfoDao;
import com.thirdgroup.dao.base.BaseDAO;
import com.thirdgroup.pojo.entity.ManagerInfo;

import java.util.List;


public class ManagerInfoDaoImpl extends BaseDAO<ManagerInfo> implements ManagerInfoDao {
    //    根据用户名查CustomerInfo
    @Override
    public ManagerInfo selectByUsername(String username) {
        String sql="select * from manager_info where managerName=?;";
        Object[] parmas={username};
        return findOne(sql,parmas);
    }

    @Override
    public List<ManagerInfo> selectAll() {
        String sql=" select * from manager_info where role_id =2 order by managerID desc ";
        return findAll(sql,null);
    }

    @Override
    public Integer updateState(String id, String status, String date) {
        String sql=" update manager_info set managerStatus=? , updateTime=? where managerID=? ";
        Object[] params={status,date,id};
        return executeSQL(sql,params);
    }

    @Override
    public Integer add(String id, String username, String password, String formattedDate, String profilePicture) {
        String sql=" insert into manager_info(managerID,managerName,managerPassword,managerStatus,superManagerPurview,createTime,updateTime,profilePicture,role_id)\n" +
                " values(?,?,?,'使用中','manager',?,?,?,2)";
        Object[] params={id,username,password,formattedDate,formattedDate,profilePicture};
        return executeSQL(sql,params);
    }

    @Override
    public Integer delete(String managerid) {
        String sql="delete from manager_info where managerID=?";
        Object[] params={managerid};
        return executeSQL(sql,params);
    }

    @Override
    public ManagerInfo detail(String managerid) {
        String sql="select * from manager_info where managerID=?";
        Object[] params={managerid};
        return findOne(sql,params);
    }


}
